set more off
*results generated with stata SE 17
*if needed, install ebalance
*ssc install ebalance, all replace

* set working directory
cd ""

use datayearly.dta, clear

* first MK onset to first split for ``treated'' cases

tab mktosplit1

generate mktosplit1sum="."
replace mktosplit1sum="up to 5" if mktosplit1<=5
replace mktosplit1sum="up to 10" if mktosplit1<=10 & mktosplit1>5
replace mktosplit1sum="up to 15" if mktosplit1<=15 & mktosplit1>10
replace mktosplit1sum="up to 20" if mktosplit1<=20 & mktosplit1>15
replace mktosplit1sum="20 or more" if mktosplit1>20 & mktosplit1!=.

* table 2

label define order  1 "up to 5"  2 "up to 10"  3 "up to 15"  4 "up to 20"  5 ">20" 

encode  mktosplit1sum, gen(MKsplityears) label(order)
 
tab MKsplityears if mktosplit1!=.


*COX DURATION MODELS -- TIME TO FIRST SPLIT 

*data setup

stset counterdyad, id(dyadid) failure(frag == 1)

d

keep if _st==1

order dyadid year frag 

saveold dataduration.dta, version(12) replace

label variable frag "Insurgent Fragmentation"     
label variable MKactive "State-led Coll. Targeting"
label variable MKactive_alt "State-led Coll. Targeting (first)"
label variable irregular2 "Irregular War"
label variable rebsupnum "Ext. Rebel Support"
label variable excluded "Recr. from Excl. Groups"
label variable prevactive "Previously Active"
label variable fightcapnum "Fighting Capacity"
label variable terrcontnum "Territorial Control"
label variable e_v2x_neopat "Neopatrimonial Rule"
label variable dyadsfirstyear "Dyads at Conflict Onset"
label variable exclpop "Excl. Population"
label variable conflictactive "Fighting Intensity"

*efron

stcox MKactive, nohr efron vce(robust)
estimates store coxefron
estat phtest, detail

stcox MKactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr efron vce(robust)
estimates store coxaefron
estat phtest, detail

stcox MKactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum) nohr efron vce(robust)
estimates store coxbefron

*breslow

stcox MKactive, nohr breslow vce(robust)
estimates store coxbreslow
estat phtest, detail

stcox MKactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr robust breslow
estimates store coxabreslow
estat phtest, detail

stcox MKactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum) nohr robust breslow
estimates store coxbbreslow

***TABLE 4 columns I, II, III, IV:
#delimit ;
estout coxbreslow coxefron coxabreslow coxaefron, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

***TABLE 4 columns V and VI:
#delimit ;
estout coxbbreslow coxbefron, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

*efron and breslow with conflict intensity/activity

stcox MKactive conflictactive, nohr robust breslow
estimates store cox2breslow
estat phtest, detail

stcox MKactive conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr robust breslow
estimates store cox3breslow
estat phtest, detail

stcox MKactive conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum) nohr robust breslow
estimates store cox4breslow

stcox MKactive conflictactive, nohr robust efron
estimates store cox2efron
estat phtest, detail

stcox MKactive conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr robust efron
estimates store cox3efron
estat phtest, detail

stcox MKactive conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum) nohr robust efron
estimates store cox4efron

*** TABLE 20 Appendix columns I, II, III and IV

#delimit ;
estout cox2breslow cox2efron cox3breslow cox3efron, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

*** TABLE 20 Appendix columns V and VI

#delimit ;
estout cox4breslow cox4efron, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

*efron first MK only

stcox MKactive_alt, nohr robust efron
estimates store cox7efron
estat phtest, detail

stcox MKactive_alt conflictactive, nohr robust efron
estimates store cox8efron

stcox MKactive_alt irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr robust efron
estimates store cox9efron
estat phtest, detail

stcox MKactive_alt conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr robust efron
estimates store cox10efron
estat phtest, detail

stcox MKactive_alt irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum) nohr robust efron
estimates store cox11efron

stcox MKactive_alt conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum)  nohr robust efron
estimates store cox12efron

*** TABLE 21 Appendix columns I, II, III, IV

#delimit ;
estout cox7efron cox8efron cox9efron cox10efron, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

*** TABLE 21 Appendix columns V and VI

#delimit ;
estout cox11efron cox12efron, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

*breslow first MK only

stcox MKactive_alt, nohr robust breslow
estimates store cox7breslow
estat phtest, detail

stcox MKactive_alt conflictactive, nohr robust breslow
estimates store cox8breslow
estat phtest, detail

stcox MKactive_alt irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr robust breslow
estimates store cox9breslow
estat phtest, detail

stcox MKactive_alt conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop terrcontnum, nohr robust breslow
estimates store cox10breslow
estat phtest, detail

stcox MKactive_alt irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum) nohr robust breslow
estimates store cox11breslow

stcox MKactive_alt conflictactive irregular2 rebsupnum excluded prevactive fightcapnum e_v2x_neopat dyadsfirstyear exclpop, tvc(terrcontnum) nohr robust breslow
estimates store cox12breslow

*** TABLE 22 Appendix columns I, II, III, IV

#delimit ;
estout cox7breslow cox8breslow cox9breslow cox10breslow, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

*** TABLE 22 Appendix columns V and VI

#delimit ;
estout cox11breslow cox12breslow, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood Clusters N)) 
label title(Probit Estimates)  collabels(, none) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr




